﻿using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.Odbc;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class public_html_NewSiteTest_Releaseliste : System.Web.UI.Page
{
    public string SpilID = "";
    public string Format = "";
    public string PicID = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["Next"] = ""; 
            PicID = Request.QueryString["PicID"];

            DateFromMySql NewDate = new DateFromMySql();
            ReviewerMySql SQL = new ReviewerMySql();

            DivScreens.InnerHtml = "<center>";

            OdbcDataReader ScreenReader = SQL.ExecuteReader("SELECT * FROM V2_Screenshots WHERE id = " + PicID);
            if (ScreenReader.Read())
            {
                ImgScreen.ImageUrl = "screenshots/" + ScreenReader["Filnavn"].ToString();
                SpilID = ScreenReader["SpilID"].ToString();
                Format = ScreenReader["Format"].ToString();
            }

            int ScreensCounter = 0;

            int NextSetter = 0;
            int FormSetter = 0;
            int Current = 0;

            OdbcDataReader ScreensReader = SQL.ExecuteReader("SELECT * FROM V2_Screenshots WHERE SpilID = '" + SpilID + "' AND Format = '" + Format + "'");
            while (ScreensReader.Read() && ScreensCounter != 4)
            {
                if (Current != 0 && NextSetter == 0)
                {
                    Session["Next"] = ScreensReader["ID"].ToString();
                    NextSetter++;
                }

                if (ScreensReader["ID"].ToString() == PicID)
                {
                    DivScreens.InnerHtml += "<a href=\"?PicId=" + ScreensReader["ID"].ToString() + "&SpilID=" + SpilID + "\"><img border=\"0\" style=\"border:4px solid #EEEEEE;\" height=\"70px\"  width=\"90px\" src=\"screenshots/" + ScreensReader["Filnavn"].ToString() + "\"></a>&nbsp;";
                    Current++;
                }
                else
                {
                    DivScreens.InnerHtml += "<a href=\"?PicId=" + ScreensReader["ID"].ToString() + "&SpilID=" + SpilID + "\"><img border=\"0\" height=\"70px\"  width=\"90px\" src=\"screenshots/" + ScreensReader["Filnavn"].ToString() + "\"></a>&nbsp;";
                    FormSetter++;
                    //FormSetter++;
                }

                if (Current == 0 && FormSetter != 0)
                {
                    Session["Former"] = ScreensReader["ID"].ToString();
                }

                ScreensCounter++;
                if (ScreensCounter == 4)
                {
                    DivScreens.InnerHtml += "<br />";
                    ScreensCounter = 0;
                }

            }

            DivScreens.InnerHtml += "</center>";

            OdbcDataReader SpilReader = SQL.ExecuteReader("SELECT * FROM V2_Spil WHERE SpilID = '" + SpilID + "' AND Format = " + Format);
            if (SpilReader.Read())
            {
                Reviewer.Games.Games.GameCount(int.Parse(SpilReader["ID"].ToString()));
                this.Title = "Screenshots - " + SpilReader["Titel"].ToString();
                lblOverskrift.Text = "Screenshots - " + SpilReader["Titel"].ToString();

                //HtmlMeta HeaderDescription = new HtmlMeta();
                //HeaderDescription.Name = "description";
                //HeaderDescription.Content = "Screenshots til " + SpilReader["Titel"].ToString();
                //this.Header.Controls.Add(HeaderDescription);
            }
        }

        if (Session["Next"] == "")
        {
            BtmFron.Enabled = false;
        }
    }
    protected void BtmFron_Click(object sender, EventArgs e)
    {
        ReviewerMySql SQL = new ReviewerMySql();
        PicID = Session["Next"].ToString();

        OdbcDataReader ScreenReader = SQL.ExecuteReader("SELECT * FROM V2_Screenshots WHERE id = " + PicID);
        if (ScreenReader.Read())
        {
            ImgScreen.ImageUrl = "screenshots/" + ScreenReader["Filnavn"].ToString();
            SpilID = ScreenReader["SpilID"].ToString();
            Format = ScreenReader["Format"].ToString();
        }

        DivScreens.InnerHtml = "<center>";

        int ScreensCounter = 0;

        int NextSetter = 0;
        int FormSetter = 0;
        int Current = 0;

        OdbcDataReader ScreensReader = SQL.ExecuteReader("SELECT * FROM V2_Screenshots WHERE SpilID = '" + SpilID + "' AND Format = '" + Format + "'");
        while (ScreensReader.Read())
        {
            if (Current != 0 && NextSetter == 0)
            {
                Session["Next"] = ScreensReader["ID"].ToString();
                NextSetter++;
            }

            if (ScreensReader["ID"].ToString() == PicID)
            {
                DivScreens.InnerHtml += "<a href=\"?PicId=" + ScreensReader["ID"].ToString() + "&SpilID=" + SpilID + "\"><img border=\"0\" style=\"border:4px solid #EEEEEE;\" height=\"70px\"  width=\"90px\" src=\"screenshots/" + ScreensReader["Filnavn"].ToString() + "\"></a>&nbsp;";
                Current++;
            }
            else
            {
                DivScreens.InnerHtml += "<a href=\"?PicId=" + ScreensReader["ID"].ToString() + "&SpilID=" + SpilID + "\"><img border=\"0\" height=\"70px\"  width=\"90px\" src=\"screenshots/" + ScreensReader["Filnavn"].ToString() + "\"></a>&nbsp;";
                FormSetter++;
                //FormSetter++;
            }

            if (Current == 0 && FormSetter != 0)
            {
                Session["Former"] = ScreensReader["ID"].ToString();
            }

            ScreensCounter++;

            if (ScreensCounter == 4)
            {
                DivScreens.InnerHtml += "<br />";
                ScreensCounter = 0;
            }

        }

        DivScreens.InnerHtml += "</center>";
        
    }

    protected void BtmBack_Click(object sender, EventArgs e)
    {
        ReviewerMySql SQL = new ReviewerMySql();
        PicID = Session["Former"].ToString();
        BtmFron.Enabled = true;

        OdbcDataReader ScreenReader = SQL.ExecuteReader("SELECT * FROM V2_Screenshots WHERE id = " + PicID);
        if (ScreenReader.Read())
        {
            ImgScreen.ImageUrl = "screenshots/" + ScreenReader["Filnavn"].ToString();
            SpilID = ScreenReader["SpilID"].ToString();
            Format = ScreenReader["Format"].ToString();
        }

        DivScreens.InnerHtml = "<center>";

        int ScreensCounter = 0;

        int NextSetter = 0;
        int FormSetter = 0;
        int Current = 0;

        OdbcDataReader ScreensReader = SQL.ExecuteReader("SELECT * FROM V2_Screenshots WHERE SpilID = '" + SpilID + "' AND Format = '" + Format + "'");
        while (ScreensReader.Read())
        {
            if (Current != 0 && NextSetter == 0)
            {
                Session["Next"] = ScreensReader["ID"].ToString();
                NextSetter++;
            }

            if (ScreensReader["ID"].ToString() == PicID)
            {
                DivScreens.InnerHtml += "<a href=\"?PicId=" + ScreensReader["ID"].ToString() + "&SpilID=" + SpilID + "\"><img border=\"0\" style=\"border:4px solid #EEEEEE;\" height=\"70px\"  width=\"90px\" src=\"screenshots/" + ScreensReader["Filnavn"].ToString() + "\"></a>&nbsp;";
                Current++;
            }
            else
            {
                DivScreens.InnerHtml += "<a href=\"?PicId=" + ScreensReader["ID"].ToString() + "&SpilID=" + SpilID + "\"><img border=\"0\" height=\"70px\"  width=\"90px\" src=\"screenshots/" + ScreensReader["Filnavn"].ToString() + "\"></a>&nbsp;";
                FormSetter++;
                //FormSetter++;
            }

            if (Current == 0 && FormSetter != 0)
            {
                Session["Former"] = ScreensReader["ID"].ToString();
            }

            ScreensCounter++;

            if (ScreensCounter == 4)
            {
                DivScreens.InnerHtml += "<br />";
                ScreensCounter = 0;
            }
        } 
        DivScreens.InnerHtml += "</center>";
    }
}